package edu.sctu.zhu.controller;

import edu.sctu.zhu.bean.Goods;
import edu.sctu.zhu.dao.GoodsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by admin on 2015/12/16.
 */
@Controller
public class MainController {

    @Autowired
    private GoodsDao goodsDao;
    //shoppingCar
    @RequestMapping(value = "/cart/orderConfirmation/{id}", method = RequestMethod.GET)
    public String UploadOrderConfirmation(HttpServletResponse response,@PathVariable Long id) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/cart/orderConfirmation";
    }

    @RequestMapping(value = "/cart/paymentMode/{id}", method = RequestMethod.GET)
    public String UploadPaymentMode(HttpServletResponse response,@PathVariable String id) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/cart/paymentMode";
    }

    @RequestMapping(value = "/cart/shoppingCart", method = RequestMethod.GET)
    public String UploadShoppingCart(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/cart/shoppingCart";
    }

    @RequestMapping(value = "/cart/productDetails", method = RequestMethod.GET)
    public String UploadProductDetails(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/cart/productDetails";
    }


    //my
    @RequestMapping(value = "/my/personalCenter", method = RequestMethod.GET)
    public String UploadPersonalCenter(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/personalCenter";
    }

    @RequestMapping(value = "/my/changeInfo", method = RequestMethod.GET)
    public String UploadChangeInfo(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/changeInfo";
    }

    @RequestMapping(value = "/my/messageCenter", method = RequestMethod.GET)
    public String UploadMessageCenter(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/messageCenter";
    }

    @RequestMapping(value = "/my/myOrder", method = RequestMethod.GET)
    public String UploadMyOrder(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/myOrder";
    }

    @RequestMapping(value = "/my/address", method = RequestMethod.GET)
    public String UploadAddress(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/address";
    }

    @RequestMapping(value = "/my/cardCoupons", method = RequestMethod.GET)
    public String UploadCardCoupons(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/cardCoupons";
    }

    @RequestMapping(value = "/my/collection", method = RequestMethod.GET)
    public String UploadCollection(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/collection";
    }

    @RequestMapping(value = "/my/guessYouLove", method = RequestMethod.GET)
    public String UploadGuessYouLove(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/guessYouLove";
    }

    @RequestMapping(value = "/my/add_address", method = RequestMethod.GET)
    public String UploadAdd_address(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/my/add_address";
    }


    //goods
    @RequestMapping(value = "/goods/index", method = RequestMethod.GET)
    public String UploadIndex(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/index";
    }

    @RequestMapping(value = "/goods/search", method = RequestMethod.GET)
    public String UploadSearch(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/search";
    }

    @RequestMapping(value = "/goods/searchResult", method = RequestMethod.GET)
    public String UploadSearchResult(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/searchResult";
    }

    @RequestMapping(value = "/goods/category_detail/{id}", method = RequestMethod.GET)
    public String UploadSearchResult(HttpServletResponse response,@PathVariable String id) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/detail_category"; 
    }

    @RequestMapping(value = "/myindex", method = RequestMethod.GET)
    public String myindex(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/myindex";
    }

    @RequestMapping(value = "/goods/productDetails", method = RequestMethod.GET)
    public String UploadProductionDetails(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/productDetails";
    }

    @RequestMapping(value = "/goods/productDetails1", method = RequestMethod.GET)
    public String UploadProductionDetails1(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/productDetails1";
    }

    @RequestMapping(value = "/goods/productionLists", method = RequestMethod.GET)
    public String UploadProductionLists(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/productionLists";
    }

    @RequestMapping(value = "/goods/productionList", method = RequestMethod.GET)
    public String UploadProductionListss(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/productionList";
    }

    @RequestMapping(value = "/goods/cloth", method = RequestMethod.GET)
    public String UploadCloth(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/cloth";
    }

    @RequestMapping(value = "/goods/cloth/cloth-mianyi", method = RequestMethod.GET)
    public String UploadCloth1(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/cloth/cloth-mianyi";
    }

    @RequestMapping(value = "/goods/dianqi", method = RequestMethod.GET)
    public String UploadDianQi(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/dianqi";
    }

    @RequestMapping(value = "/goods/ershou", method = RequestMethod.GET)
    public String UploadErShou(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/ershou";
    }

    @RequestMapping(value = "/goods/jiaju", method = RequestMethod.GET)
    public String UploadJiaJu(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/jiaju";
    }

    @RequestMapping(value = "/goods/lingshi", method = RequestMethod.GET)
    public String UploadLingShi(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/lingshi";
    }

    @RequestMapping(value = "/goods/baby", method = RequestMethod.GET)
    public String UploadBaby(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/baby";
    }

    @RequestMapping(value = "/goods/diannao", method = RequestMethod.GET)
    public String UploadDianNao(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/diannao";
    }

    @RequestMapping(value = "/goods/kuzi", method = RequestMethod.GET)
    public String UploadKuZi(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/kuzi";
    }

    @RequestMapping(value = "/goods/liwu", method = RequestMethod.GET)
    public String UploadLiWu(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/liwu";
    }

    @RequestMapping(value = "/goods/other", method = RequestMethod.GET)
    public String UploaOther(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/other";
    }

    @RequestMapping(value = "/goods/shenghuoyongping", method = RequestMethod.GET)
    public String UploadLife(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/shenghuoyongping";
    }

    @RequestMapping(value = "/goods/shuma", method = RequestMethod.GET)
    public String UploadShuma(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/shuma";
    }

    @RequestMapping(value = "/goods/wanju", method = RequestMethod.GET)
    public String UploadWanJu(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/wanju";
    }

    @RequestMapping(value = "/goods/wenju", method = RequestMethod.GET)
    public String UploadWenJu(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/wenju";
    }


    @RequestMapping(value = "/goods/detail/{id}",method = RequestMethod.GET)
    public String getTest(@PathVariable Long id,HttpServletResponse response){
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/productDetails";
    }

    @RequestMapping(value = "/goods/waimai", method = RequestMethod.GET)
    public String UploadWaiMai(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/waimai";
    }

    @RequestMapping(value = "/goods/detailsList", method = RequestMethod.GET)
    public String UploadDetailsList(HttpServletResponse response) {
        response.setHeader("X-Frame-Options", "AllowAll");
        return "/goods/detailsList";
    }

    @RequestMapping(value = "/cart/confirm", method = RequestMethod.POST)
    public ModelAndView confirmcat(HttpServletResponse response,HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        response.setHeader("X-Frame-Options", "AllowAll");
        int flag = Integer.decode(request.getParameter("flag"));
        String allPrice = request.getParameter("allPrice");
        String allNumber = request.getParameter("allNumber");
        List<Goods> goodsList = new ArrayList<>();
        for (int i = 0; i <flag; i++) {
            String id= request.getParameter("id"+i);
            String number= request.getParameter("number"+i);
            Goods goods = goodsDao.findOne(Long.decode(id));
            goods.setNumber(number);
            goodsList.add(goods);
        }
        modelAndView.addObject("allPrice",allPrice);
        modelAndView.addObject("allNumber",allNumber);
        modelAndView.addObject("goodsList",goodsList);
        modelAndView.setViewName("/cart/ordersConfirmation");
        return modelAndView;
    }









//    @RequestMapping(value = "/goods/detail",method = RequestMethod.GET)
//    public String detailGoods(){
//        ModelAndView
//    }

}
